package com.example.service.Impl;

import com.example.Constants.SystemConstants;
import com.example.utils.SecurityUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("ps")
public class PermissionService {

    /**
     * 判断用户是否具有权限
     * @param permission  要判断的权限
     * @return
     */
    public boolean hasPermission(String permission) {
        //如果为超级管理员
        if (SystemConstants.ADMIN.equals(SecurityUtils.getLoginUser().getUser().getAuthority())) {
            return true;
        }
        //其他情况
        List<String> permissionList = SecurityUtils.getLoginUser().getPermission();
        return permissionList.contains(permission);
    }
}